<?php

namespace Managers;

use \Managers\Widget\AbstractWidget;

class WidgetLoader
{
    public static function getWidgets()
    {
        $widgets = array();
        $blockManager = new Block();
        $blocks = $blockManager->getActiveList();
        foreach ($blocks as $block) {
            $class = $block['class'];
            if (!class_exists($class)) {
                throw new \Exception("Class $class does not exist.");
            }
            $widget = new $class();
            if (!($widget instanceof AbstractWidget)) {
                throw new \Exception("Widget {$block['id']} does not extend AbstractWidget");
            }
            $widgets[] = $widget;
        }

        return $widgets;
    }
}
